package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.Setmeal;
import com.itheima.pojo.SetmealHotVO;
import com.itheima.pojo.SetmealReportVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealDao {

    Page<Setmeal> pageQuery(String queryString);

    void save(Setmeal setmeal);

    @Select("select * from t_setmeal where id = #{id}")
    Setmeal findById(Integer id);

    Setmeal findByIdDetails(Integer setmealId);

    @Select("select img from t_setmeal where id = #{id}")
    String findImgById(Integer id);

    void update(Setmeal setmeal);

    @Delete("delete from t_setmeal where id = #{id}")
    void delete(Integer id);

    List<SetmealReportVO> getSetmealReport(LocalDate dateBegin, LocalDate dateEnd);

    /**
     * 获取30天内排名前3的套餐数据
     * @return
     */
    @Select("select s.name `name`,count(*) `setmealCount`,(count(*)/(select count(*) from t_order)) as `proportion` " +
            "from t_setmeal s,t_order o where s.id = o.setmeal_id and o.orderDate >= #{dateBegin} " +
            "GROUP BY o.setmeal_id ORDER BY setmealCount desc LIMIT 3 ")
    List<SetmealHotVO> getHotSetmeal(LocalDate dateBegin);

    @Select("select * from t_setmeal")
    List<Setmeal> getSetmeal();
}
